﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PresentationTier
{
    /// <summary>
    /// Parital ManagersForm class.
    /// </summary>
    public partial class ManagersForm : Form
    {
        /*constants*/
        private const string MANAGER_NAME = "ManagerName";

        /*objects*/
        private BusinessLogicTier.ManagersBLT ManagersBLT;
        private BindingSource ManagersBindingSource;

        /// <summary>
        /// Default constructor for ArtistForm.
        /// </summary>
        public ManagersForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Initializes and set bindingsources.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ManagersForm_Load(object sender, EventArgs e)
        {
            this.ManagersBLT = new BusinessLogicTier.ManagersBLT();
            this.ManagersBindingSource = new BindingSource();
            this.ManagersBindingSource.DataSource = this.ManagersBLT.GetManagers();
            this.managersDataGridView.DataSource = this.ManagersBindingSource;
            this.viewManagerBindingNavigator.BindingSource = this.ManagersBindingSource;
            this.addManagersBindingNavigator.BindingSource = this.ManagersBindingSource;
            this.delManagersBindingNavigator.BindingSource = this.ManagersBindingSource;
            this.managerNameListBox.DataSource = this.ManagersBindingSource;
            this.managerNameListBox.DisplayMember = MANAGER_NAME;
        }

        /// <summary>
        /// InsertManagerButton click event calls the insert method from the ManagersBLT class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InsertManagerButton_Click(object sender, EventArgs e)
        {
            /*insert manager with paramter values from event textbox controls*/
            this.ManagersBLT.InsertManager(managerNameTextBox.Text, managerCompanyTextBox.Text, 
                managerAddressTextBox.Text, managerCityTextBox.Text, managerRegionTextBox.Text, 
                managerPostalCodeTextBox.Text, managerCountryTextBox.Text, managerEmailTextBox.Text, 
                managerPhoneTextBox.Text, managerFaxTextBox.Text);

            MessageBox.Show(managerNameTextBox.Text + " manager inserted.", "Insert Confirmation");

            /*clear all textbox controls*/
            this.managerNameTextBox.Clear();
            this.managerCompanyTextBox.Clear();
            this.managerAddressTextBox.Clear();
            this.managerCityTextBox.Clear();
            this.managerCountryTextBox.Clear();
            this.managerEmailTextBox.Clear();
            this.managerFaxTextBox.Clear();
            this.managerPhoneTextBox.Clear();
            this.managerPostalCodeTextBox.Clear();
            this.managerRegionTextBox.Clear();

            /*reset bindingsource after insert has executed*/
            this.ManagersBindingSource.DataSource = this.ManagersBLT.GetManagers();
            this.ManagersBindingSource.ResetBindings(true);
        }

        /// <summary>
        /// DeleteManagerButton click event calls the delete method from the ManagersBLT class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteManagerButton_Click(object sender, EventArgs e)
        {
            /*delete artist that user selected from the artistNameListbox control*/
            string managerId = this.managersDataGridView.Rows[this.managersDataGridView.CurrentRow.Index].Cells[0].Value.ToString();
            this.ManagersBLT.DeleteManager(managerId);

            MessageBox.Show("Manager has been deleted.", "Delete Confirmation");

            /*reset bindingsource after insert has executed*/
            this.ManagersBindingSource.DataSource = this.ManagersBLT.GetManagers();
            this.ManagersBindingSource.ResetBindings(true);
        }        
    }
}
